package tongcheng.com.tongcheng.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import tongcheng.com.tongcheng.R;
import tongcheng.com.tongcheng.base.BaseViewHolder;
import tongcheng.com.tongcheng.bean.FuwuLeixingBean;

/**
 * Created by P on 2017/7/26.
 */

public class FuwuLeixingAdapter extends RecyclerView.Adapter<FuwuLeixingAdapter.FuwuLeixingViewHolder> {
    public Context mContext;
    public List<FuwuLeixingBean.DataBean> datas;
    public FuwuLeixingAdapter(Context context,List<FuwuLeixingBean.DataBean> datas) {
        this.mContext = context;
        this.datas = datas;
    }

    @Override
    public FuwuLeixingViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(mContext, R.layout.item_fuwuleixing, null);
        FuwuLeixingViewHolder fuwuLeixingViewHolder = new FuwuLeixingViewHolder(view);
        return fuwuLeixingViewHolder;
    }

    @Override
    public void onBindViewHolder(FuwuLeixingViewHolder holder, int position) {
        FuwuLeixingBean.DataBean dataBean = datas.get(position);
        holder.item_fuwuleixing_title.setText(dataBean.name);

        GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 3);
        holder.item_fuwuleixing_rc.setLayoutManager(gridLayoutManager);
        LeiXingAdapter leiXingAdapter = new LeiXingAdapter(mContext,dataBean.sonList);
        holder.item_fuwuleixing_rc.setAdapter(leiXingAdapter);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public class FuwuLeixingViewHolder extends BaseViewHolder{
        public RecyclerView item_fuwuleixing_rc;
        public TextView item_fuwuleixing_title;
        public FuwuLeixingViewHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void init(View itemview) {
             item_fuwuleixing_rc = itemview.findViewById(R.id.item_fuwuleixing_rc);
             item_fuwuleixing_title = itemview.findViewById(R.id.item_fuwuleixing_title);
        }
    }

}
